package com.blackitheima2.polymorphic.test4;

public class TestDogAndCat {
    public static void main(String[] args) {
        useAnimal(new Dog());
        useAnimal(new Cat());


    }
    public static void useAnimal(Animal a){
        a.eat();

        if(a instanceof Dog){
            Dog d= (Dog) a;
            d.watchHome();
        }
    }
}
//父类
 class Animal{
    public  void eat(){
        System.out.println("动物吃饭");
    }
}
//猫子类
class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }
}
//狗子类
class Dog extends Animal{
    @Override
    public void eat() {
        System.out.println("狗吃肉");
    }
    public void watchHome(){
        System.out.println("小狗看家");
    }
}
